Release 10.1A: OpenEdge Application Server:
Developing AppServer Applications


Connection examples

The following code examples show how a client application specifies the connection and application arguments to connect an AppServer or application service.

Connecting to a session-managed AppServer

In this session-managed connection example, the -AppService, -H, and -S parameters are passed as the connection-parameters argument to the CONNECT( ) method. Specific userid and password values are also passed as connection arguments. A value is not supplied for the appserver-info argument, as shown:

DEFINE VARIABLE hAppSrv AS HANDLE  NO-UNDO.
DEFINE VARIABLE ret     AS LOGICAL NO-UNDO.

CREATE SERVER hAppSrv.
ret = hAppSrv:CONNECT
               ("-AppService inventory -H zeus -S 5162","SMITH","STARSHIP").
IF NOT ret THEN
  RETURN ERROR "Failed to connect to Inventory AppServer".

                   .
                   .
                   .

ret = hAppSrv:DISCONNECT().
DELETE OBJECT hAppSrv. 

This code tries to connect an AppServer that supports the application service, inventory. It sends its connection request to a NameServer that runs on a machine with the host name, zeus and is listening on UDP port 5162.

When the CONNECT( ) method executes, the NameServer provides the location of an AppServer broker to the client that supports the inventory application service. The NameServer chooses the AppServer broker randomly from among all AppServers that support the application service and according to load balance settings (if any) established for the application service. The client then connects to the broker, passing the last two method arguments as the first two parameters of the AppServer Connect procedure. The client passes a value of "SMITH" for userid and "STARSHIP" for password. It passes the Unknown value (?) for appserver-info because a value is not supplied for it.

Note: The previous code example, and all remaining code examples in this chapter, are presented in simplified form for discussion purposes. In actual practice, you might use the Parameter File (-pf) parameter as the connection-parameters argument and variables to store the userid and password (probably encrypted).

Connecting to a session-free AppServer

In this session-free connection example, the connection-parameters argument to the CONNECT( ) method contains the -AppService, -H, -S, -sessionModel, and -initialConnections parameters, as shown:

DEFINE VARIABLE hInventory AS HANDLE  NO-UNDO.
DEFINE VARIABLE ret     AS LOGICAL NO-UNDO.

CREATE SERVER hInventory.
ret = hInventory:CONNECT("-AppService inventory -S 5163 -H 4glservices 
                       -sessionModel Session-free -initialConnections 25").
IF NOT ret THEN
  RETURN ERROR "Failed to connect to Inventory application service".
IF ERROR-STATUS:ERROR THEN DO:
  ret = hInventory:DISCONNECT().
  RETURN ERROR RETURN-VALUE.
END.
.
.
.

ret = hInventory:DISCONNECT().
DELETE OBJECT hInventory. 

This code tries to connect the inventory application service by setting up an initial connection pool containing 25 physical connections to AppServers that support this application service. It sends its connection request to a NameServer that runs on a machine with the host name, 4glservices and is listening on UDP port 5163. When the CONNECT( ) method executes, the NameServer returns the location of an AppServer broker that supports the inventory application service, once for each of the 25 requested physical connections. The client then creates the 25 physical connections to these brokers, distributed randomly and according to load balance settings (if any) established for the application service.


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095